import qrcode
import matplotlib.pyplot as plt  # plt 用于显示图片
import matplotlib.image as mpimg  # mpimg 用于读取图片
from qrcode.image.styledpil import StyledPilImage
from qrcode.image.styles.moduledrawers import RoundedModuleDrawer, SquareModuleDrawer
from qrcode.image.styles.colormasks import RadialGradiantColorMask, SquareGradiantColorMask

text = eval(input("你要计算几元函数函数："))
if text == 1:
    a = eval(input("x"))
    x = 3 * a
    text = '3 * x ='
    text += str(x)

# 纠错设置为高
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_H)
# 构建二维码
data = 'hello world!'
# img = qrcode.make(data)
img = qr.make_image(image_factory=StyledPilImage, color_mask=SquareGradiantColorMask(),module_drawer=RoundedModuleDrawer())
# 显示图片格式，为qrcode.image.pil.PilImage
print(type(img))
# 保存图片
img.save("test2.png")


img = mpimg.imread('./test2.png')  #

# 结果展示
plt.rcParams['font.sans-serif'] = ['SimHei']  # 中文乱码
plt.subplot(121)
# imshow()对图像进行处理，画出图像，show()进行图像显示
plt.imshow(img)

plt.title(text)
# 不显示坐标轴
plt.axis('off')

plt.show()